package com.mikufufu.blog.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mikufufu.blog.common.entity.AjaxResult;
import com.mikufufu.blog.common.entity.Query;
import com.mikufufu.blog.model.entity.Archives;
import com.mikufufu.blog.service.ArchivesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/archives")
@Api(tags = "合集")
public class ArchivesAdminController {

    @Autowired
    private ArchivesService archivesService;

    @PostMapping("/add")
    @ApiOperation("添加")
    public AjaxResult<Boolean> add(@RequestBody Archives archives) {
        return AjaxResult.status(archivesService.save(archives));
    }

    @PutMapping("/update")
    @ApiOperation("更新")
    public AjaxResult<Boolean> update(@RequestBody Archives archives) {
        return AjaxResult.status(archivesService.updateById(archives));
    }

    @DeleteMapping("/delete")
    @ApiOperation("通过主键删除")
    @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "Integer")
    public AjaxResult<Boolean> delete(Integer id) {
        return AjaxResult.status(archivesService.removeById(id));
    }

    @GetMapping("/detail")
    @ApiOperation("通过主键获取信息")
    @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "Integer")
    public AjaxResult<Archives> detail(Integer id) {
        return AjaxResult.data(archivesService.getById(id));
    }

    @GetMapping("/list")
    @ApiOperation("获取归档列表")
    public AjaxResult<List<Archives>> list() {
        return AjaxResult.data(archivesService.list());
    }

    @GetMapping("/page")
    @ApiOperation("分页获取归档列表")
    public AjaxResult<IPage<Archives>> page(Query query) {
        return AjaxResult.data(archivesService.page(query.getPage()));
    }

}
